package com.omesoft.hksnore.util.snore;

/**
 * Created by Omesoft on 2017/3/5.
 *
 * 分别工具类，提供分贝计算方法
 */

public class DecibelUtil {
    private final String TAG = "DecibelUtil";

    public static double getDecibel(short[] buffer, int length) {
        long sum = 0;
        for (short buf : buffer) {
            sum += Math.pow(buf, 2);
        }
//		Log.d("sherlock", "sum::" + sum);
        return 10 * Math.log10(sum / (double) length);
    }

    public static double getDecibel2(short[] buffer, int length) {
        long sum = 0;
        for (short buf : buffer) {
            sum += Math.pow(buf, 2);
        }
        return (Math.log10(Math.sqrt(sum / (double) buffer.length) / 32768f) * 20 + 100);
    }

    public static double getDecibe3(short[] buffer, int length) {
        long sum = 0;
        for (short buf : buffer) {
            sum += Math.pow(buf, 2);
        }
        return (20 * Math.log10(Math.sqrt(sum / (double) length) / 32768f)) + 90;
    }
}
